package org.water.garden.view;

import org.water.garden.R;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ActivityIconAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivityListAdapter extends ActivityIconAdapter {

	private final PackageManager mPM;

	public ActivityListAdapter(Context context, Intent intent) {
		super(context, intent);
		mPM = context.getPackageManager();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if (convertView == null)
			view = mInflate.inflate(R.layout.activity_list_row, parent, false, null);
		else
			view = convertView;
		bindView(view, (ResolveInfo) mList.get(position));
		return view;
	}

	private final void bindView(View view, ResolveInfo info) {
		TextView text = (TextView) view.findViewById(android.R.id.text1);
		ImageView icon = (ImageView) view.findViewById(R.id.activity_icon);
		text.setText(info.loadLabel(mPM));
		icon.setImageDrawable(info.loadIcon(mPM));
	}
}
